package com.gdhengdian.map;


import com.gdhengdian.map._interface.Map;
import com.gdhengdian.map._interface._impl.LinkedListMap;
import com.gdhengdian.map._interface._impl.TreeMap;

import java.util.Random;

/**
 * @author HD-0078 杨炜耀
 * @date 2021-4-8 15:46
 */
public class MapMainTest {

    public static void main(String[] args) {
        Map<Integer, Integer> linkedListMap = new LinkedListMap<>();
        Map<Integer, Integer> treeMap = new TreeMap<>();
        for (int i = 0; i < 100; i++) {
            linkedListMap.put(i, i << 2);
            treeMap.put(i, i * i);
        }
        println(linkedListMap);
        println(treeMap);
    }

    private static void println(Map<Integer, Integer> map){
        String simpleName = map.getClass().getSimpleName();
        Random random = new Random();
        int number = random.nextInt(100);
        System.out.println("old " + simpleName + " map size is: " + map.size());
        System.out.println(simpleName + " map key if contains \"" + number + "\": " + map.contains(number));
        System.out.println(simpleName + " map if isEmpty: " + map.isEmpty());
        System.out.println(simpleName + "map get value: " + map.get(number) + " by key: " + number);
        map.remove(number);
        System.out.println("removed of new " + simpleName + " collection size is: " + map.size() + "\n");
    }
}
